<template>
  <div class="about">
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="nickName" label="昵称" width="180">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>
      <el-table-column prop="header" label="头像" width="180">
      </el-table-column>
      <el-table-column prop="status" label="状态" width="180">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="info">有效</el-tag>
          <el-tag v-if="scope.row.status == 0" type="info">无效</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加 -->
    <p style="text-align: left">
      <el-button type="primary" @click="dialogFormAdd = true">添加</el-button>
    </p>
    <el-dialog title="添加人员" :visible.sync="dialogFormAdd">
      <el-form :model="form">
        <el-form-item label="昵称">
          <el-input v-model="form.nickName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="头像">
          <el-input v-model="form.header" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-select v-model="form.status" placeholder="状态">
            <el-option label="有效" value="1"></el-option>
            <el-option label="无效" value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormAdd = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>

    <div>
      <el-pagination background layout="prev, pager, next" :page-size="3" :total="1000"
      @prev-click="prePage" @next-click="nextPage" @current-change="dPage"
      >
      </el-pagination>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      tableData: [],

      dialogFormAdd: false,
      formLabelWidth: "120px",
      form: {
        nickName: "",
        name: "",
        email: "",
        status: null,
      },

      pager: {
        _page: 1,
        _limit:3,
      },
    };
  },
  created() {
    this.query();
  },

  methods: {
    

    query() {
      this.$api.__api_list_users(this.pager).then((data) => {
        this.tableData = data;

      });
    },
    //删除
    handleDelete(index, row) {
      this.$api.__api_list_delete(row).then((data) => {
        this.query();
      });
    },
    
    //添加
    add() {
      this.$api.__api_list_add(this.form).then(() => {
        this.form = {};
        this.query();
        this.dialogFormAdd = false;
      });
    },
    //翻页
    prePage(){
      
      this.pager._page--;
      
      this.query();
      console.log(123);
    },
     nextPage(){
      this.pager._page++;
      this.query();
    },
     dPage(i){
      this.pager._page=i;
      this.query();
    },
  },
};
</script>
<style scoped>
</style>

